﻿using System.Windows.Input;
using Columbus;
using Columbus.Commands;
using HelloColumbusApplication.MessageBoxFeature;

namespace HelloColumbusApplication
{
    public class HomePageViewModel : ViewModel
    {
        public string Message { get; private set; }
        public string Name { get; set; }

        public HomePageViewModel(string message)
        {
            Message = message;
            ShowGreetingPageCommand = new DelegateCommand(() => Navigator.NavigateTo<HomeController>(c => c.SayHelloTo(Name)));
            ShowAboutDialogCommand = new DelegateCommand(() => Navigator.NavigateTo<HomeController>(c => c.AboutDialog()));
            ShowAppSettingsCommand = new DelegateCommand(() => Navigator.NavigateTo<HomeController>(c => c.AppSettingsPage()));
            ShowMessageBoxCommand = new DelegateCommand(() => Navigator.NavigateTo<MessageBoxController>(c => c.OkCancelChoice()));
        }

        public ICommand ShowAboutDialogCommand { get; set; }

        public ICommand ShowMessageBoxCommand { get; set; } 

        public ICommand ShowGreetingPageCommand { get; set; }

        public ICommand ShowAppSettingsCommand { get; set; }

        // This view model doesn't have default constructor so to make it restorable (able to survive tombstone)
        // and get restored with whatever was initially passed to the constructor 
        // we are saving constructor parameters in a view state.
        // Try clicking phone start button when you are on the Home page to simulate tombstoning 
        // then click phone Back button - this view model will be restored with saved constructor parameter.
        // If you don't need it - just remove this method and add default constructor - your view model will be restored 
        // by calling default constructor then

        protected override void OnDeactivated(IViewState state)
        {
            base.OnDeactivated(state);
            state.SaveConstructorParameter("message", Message);
        }
    }
}
